
/*
 * (a)  (C) 1990 by Adobe Systems Incorporated. All rights reserved.
 *
 * (b)  If this Sample Code is distributed as part of the Display PostScript
 *	System Software Development Kit from Adobe Systems Incorporated,
 *	then this copy is designated as Development Software and its use is
 *	subject to the terms of the License Agreement attached to such Kit.
 *
 * (c)  If this Sample Code is distributed independently, then the following
 *	terms apply:
 *
 * (d)  This file may be freely copied and redistributed as long as:
 *	1) Parts (a), (d), (e) and (f) continue to be included in the file,
 *	2) If the file has been modified in any way, a notice of such
 *      modification is conspicuously indicated.
 *
 * (e)  PostScript, Display PostScript, and Adobe are registered trademarks of
 *	Adobe Systems Incorporated.
 * 
 * (f) THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO
 *	CHANGE WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED
 *	AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
 *	ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY
 *	OR LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO
 *	WARRANTY OF ANY KIND (EXPRESS, IMPLIED OR STATUTORY)
 *	WITH RESPECT TO THIS INFORMATION, AND EXPRESSLY
 *	DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, 
 *	FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT
 *	OF THIRD PARTY RIGHTS.
 */

/*
   filename	: hdshowaux.m
   date created	: 22-oct-90
   last updated	: 12-dec-90
   author		: ross a jeynes
   porter		: ken r fromm
   purpose	: auxilary routines to fill the show structure
*/

#import "hdshowany.h"
#import <stdlib.h>
#import <string.h>

void ResetShowStruct(ShowStruct *show)
{
	show->text = NULL;
	memset((void *) show->attr, 0, show->textlen * sizeof(unsigned int));

	show->textlen = 0;

	show->prkernlen = 0;
	show->vkernlen = 0;
	show->absmovlen = 0;
	show->spaceadjlen = 0;
	show->trackkernlen = 0;
}

void AllocShowStruct(ShowStruct *show)
{
	show->textmax		= 128;

	show->prkernmax		= 16;
	show->vkernmax		= 16;
	show->absmovmax	= 16;
	show->spaceadjmax	= 16;
	show->trackkernmax	= 16;

	show->attr			= (unsigned int *) malloc(show->textmax * sizeof(unsigned int));

	show->prkern			= (NXCoord *) malloc(show->prkernmax * sizeof(NXCoord));
	show->vkern			= (NXCoord *) malloc(show->vkernmax * sizeof(NXCoord));
	show->absmov		= (NXPoint *) malloc(show->absmovmax * sizeof(NXPoint));
	show->spaceadj		= (NXCoord *) malloc(show->spaceadjmax * sizeof(NXCoord));
	show->trackkern		= (NXCoord *) malloc(show->trackkernmax * sizeof(NXCoord));

	ResetShowStruct(show);
}

void FreeShowStruct(ShowStruct *show)
{
	free(show->attr);

	free(show->prkern);
	free(show->vkern);
	free(show->absmov);
	free(show->spaceadj);
	free(show->trackkern);
}

void AddString(ShowStruct *show, char *string)
{
	show->textlen = strlen(string);
	show->text = string;
	if (show->textlen >= show->textmax)
	{
		show->textmax = show->textmax * 2;
    		show->attr = (unsigned int *) realloc(show->attr, show->textmax * sizeof(unsigned int));	}
}

void AddMoveto(ShowStruct *show, int index, NXCoord x, NXCoord y)
{
	if (show->absmovlen >= show->absmovmax)
	{
		show->absmovmax = show->absmovmax * 2;
    		show->absmov = (NXPoint *) realloc(show->absmov,
						show->absmovmax * sizeof(NXPoint));
	}	

	show->attr[index] |= SA_ABSMOV;
	show->absmov[show->absmovlen].x = x;
	show->absmov[show->absmovlen].y = y;
	show->absmovlen++;
}

void AddPairKern(ShowStruct *show, int index, NXCoord value)
{
	if (show->prkernlen >= show->prkernmax)
	{
		show->prkernmax = show->prkernmax * 2;
    		show->prkern = (NXCoord *) realloc(show->prkern,
					show->prkernmax * sizeof(NXPoint));
	}	

	show->attr[index] |= SA_PRKERN;
	show->prkern[show->prkernlen] = value;
	show->prkernlen++;
}

void AddTracking(ShowStruct *show, int index, NXCoord value)
{
	if (show->trackkernlen >= show->trackkernmax)
	{
		show->trackkernmax = show->trackkernmax * 2;
    		show->trackkern = (NXCoord *) realloc(show->trackkern,
					show->trackkernmax * sizeof(NXPoint));
	}	

	show->attr[index] |= SA_TRACKADJ;
	show->trackkern[show->trackkernlen] = value;
	show->trackkernlen++;
}

void AddSpaceAdj(ShowStruct *show, int index, NXCoord value)
{
	if (show->spaceadjlen >= show->spaceadjmax)
	{
		show->spaceadjmax = show->spaceadjmax * 2;
    		show->spaceadj = (NXCoord *) realloc(show->spaceadj,
					show->spaceadjmax * sizeof(NXPoint));
	}	

	show->attr[index] |= SA_SPACEADJ;
	show->spaceadj[show->spaceadjlen] = value;
	show->spaceadjlen++;
}
